//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Globalization;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{
    public class ConditionalFormatValueObject: IOfficeXmlSerializable
    {
        public ConditionalFormatValueObject()
        {
                
        }

        internal ConditionalFormatValueObject(ConditionalFormatValueObjectType type, string value)
        {
            this.Type = type;
            this.Value = value;
        }
        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("cfvo"))
            {
                Type = c.GetEnum<ConditionalFormatValueObjectType>("type");
                Value = c.GetOptionalString("val");
                GreaterThanOrEqual = c.GetOptionalBoolean("gte", true);
                c.WarnIf("ExtLst");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (var c = context.Write("cfvo"))
            {
                c.SetEnum("type", Type);
                c.SetOptionalString("val", Value);
                c.SetOptionalBoolean("gte", GreaterThanOrEqual, true);
                c.WarnIf("ExtLst");
            }
        }

        #endregion

        public ExtensionElement Extension { get; set; }
        public ConditionalFormatValueObjectType Type { get; set; }
        public string Value { get; set; }
        internal double NumericValue { get { return double.Parse(Value, CultureInfo.InvariantCulture); } }
        private bool _greaterThanOrEqual = true;
        public bool GreaterThanOrEqual
        {
            get { return _greaterThanOrEqual; }
            set { _greaterThanOrEqual = value; }
        }

        internal ConditionalFormatValueObject Clone()
        {
            return (ConditionalFormatValueObject) MemberwiseClone();
        }
    }
}
